/*
  * Copyright (c) 2016 MediaTek Inc.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
  * General Public License (GPL) Version 2, available from the file
  * COPYING in the main directory of this source tree, or the
  * BSD license below:
  *
  *     Redistribution and use in source and binary forms, with or
  *     without modification, are permitted provided that the following
  *     conditions are met:
  *
  *      - Redistributions of source code must retain the above
  *        copyright notice, this list of conditions and the following
  *        disclaimer.
  *
  *      - Redistributions in binary form must reproduce the above
  *        copyright notice, this list of conditions and the following
  *        disclaimer in the documentation and/or other materials
  *        provided with the distribution.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */


#ifdef DOT11Z_TDLS_SUPPORT
#include "rtmp_type.h"

#ifndef __DOT11Z_TDLS_H
#define __DOT11Z_TDLS_H

/* TDLS definitions in 802.11z D13.0 specification */
#define	PROTO_NAME_TDLS				2
#define	TDLS_AKM_SUITE_1X			5	/* <ANA> */
#define	TDLS_AKM_SUITE_PSK			7

/* TDLS Action frame definition in 802.11z D13.0 specification */
#define TDLS_ACTION_CODE_SETUP_REQUEST				0
#define TDLS_ACTION_CODE_SETUP_RESPONSE				1
#define TDLS_ACTION_CODE_SETUP_CONFIRM				2
#define TDLS_ACTION_CODE_TEARDOWN					3
#define TDLS_ACTION_CODE_PEER_TRAFFIC_INDICATION	4	/* for TDLS UAPSD */
#define TDLS_ACTION_CODE_CHANNEL_SWITCH_REQUEST		5
#define TDLS_ACTION_CODE_CHANNEL_SWITCH_RESPONSE	6
#define TDLS_ACTION_CODE_PEER_PSM_REQUEST			7
#define TDLS_ACTION_CODE_PEER_PSM_RESPONSE			8
#define TDLS_ACTION_CODE_PEER_TRAFFIC_RESPONSE		9	/* for TDLS UAPSD */
#define TDLS_ACTION_CODE_DISCOVERY_REQUEST			10

/* Status codes defined in 802.11zD13.0 specification. */
#define TDLS_STATUS_CODE_WAKEUP_SCHEDULE_REJECT_BUT_ALTERNATIVE_SCHEDULE_PROVIDED	2
#define TDLS_STATUS_CODE_WAKEUP_SCHEDULE_REJECT										3
#define TDLS_STATUS_CODE_SECURITY_DISABLED											5
#define TDLS_STATUS_CODE_UNACCEPTABLE_LIFETIME										6
#define TDLS_STATUS_CODE_NOT_IN_SAME_BSS											7
#define TDLS_STATUS_CODE_INVALID_CONTENTS_OF_RSNIE									72

/* Reason codes defined in 802.11zD13.0 specification. */
#define TDLS_REASON_CODE_TEARDOWN_DUE_TO_PEER_STA_UNREACHABLE						25
#define TDLS_REASON_CODE_TEARDOWN_FOR_UNSPECIFIED_REASON							26

/* Information element ID defined in 802.11z D13.0 specification. */
#define IE_TDLS_LINK_IDENTIFIER			101
#define IE_TDLS_WAKEUP_SCHEDULE			102
#define IE_TDLS_CHANNEL_SWITCH_TIMING	104
#define IE_TDLS_PTI_CONTROL				105
#define IE_TDLS_PU_BUFFER_STATUS		106

#define TDLS_ELM_LEN_LINK_IDENTIFIER		18
#define TDLS_ELM_LEN_WAKEUP_SCHEDULE		18
#define TDLS_ELM_LEN_CHANNEL_SWITCH_TIMING	6
#define TDLS_ELM_LEN_PTI_CONTROL			5
#define TDLS_ELM_LEN_BUFFER_STATUS			3

#define TDLS_KEY_TIMEOUT			3600	/* unit: sec */

#define TDLS_LEY_LIFETIME			3600

#define FT_MIC_LEN					16
#define FT_NONCE_LEN				32

/* Information element ID defined in 802.11rD9.0 specification. */
#define IE_FT_MDIE				54
#define IE_FT_FTIE				55
#define IE_FT_TIMEOUT_INTERVAL	56
#define IE_FT_RIC_DATA			57
#define IE_FT_RIC_DESCRIPTOR	75

/* RIC Type */
#define FT_RIC_TYPE_BA			1

/* AKM SUITE */
#define FT_AKM_SUITE_1X		3
#define FT_AKM_SUITE_PSK	4

typedef union GNU_PACKED _FT_MIC_CTR_FIELD {
	/*
	   IECnt: contains the number of IEs
	   that are included int eht MIC calculation.
	 */
	struct GNU_PACKED {
#ifdef RT_BIG_ENDIAN
		UINT16 IECnt:8;
		 UINT16:8;
#else
		 UINT16:8;
		UINT16 IECnt:8;
#endif				/* endif */
	} field;
	UINT16 word;
} FT_MIC_CTR_FIELD, *PFT_MIC_CTR_FIELD;

/*
** FTIE: Fast Transition IE.
*/
typedef struct GNU_PACKED _FT_FTIE {
	FT_MIC_CTR_FIELD MICCtr;	/* 2 Octects. */
	UINT8 MIC[FT_MIC_LEN];	/* 16 Octects. */
	UINT8 ANonce[FT_NONCE_LEN];	/* 32 Octects. */
	UINT8 SNonce[FT_NONCE_LEN];	/* 32 Octects. */
	UINT8 Option[0];	/* 1:R1KHID, 2:GTK, 3:ROKHId, else:Res */
} FT_FTIE, *PFT_FTIE;

/*
** Timeout Interval IE.
*/
typedef enum _FT_TIMEOUT_INTERVAL_TYPE {
	REASSOC_DEADLINE_INTERVAL = 1,	/* TUs */
	KEY_LIFETIME_INTERVAL,	/* seconds. */
#ifdef DOT11W_PMF_SUPPORT
	ASSOC_COMEBACK_TIME,	/* TUs */
#endif /* DOT11W_PMF_SUPPORT */
	RESERVED_INTERVAL
} FT_TIMEOUT_INTERVAL_TYPE, *PFT_TIMEOUT_INTERVAL_TYPE;

typedef struct GNU_PACKED _FT_TIMEOUT_INTERVAL_IE {
	UINT8 TimeoutIntervalType;
	UINT32 TimeoutIntervalValue;
} FT_TIMEOUT_INTERVAL_IE, *PFT_TIMEOUT_INTERVAL_IE;

typedef struct GNU_PACKED _TDLS_LINK_IDENT_ELEMENT {
	UCHAR BSSID[MAC_ADDR_LEN];
	UCHAR InitiatorAddr[MAC_ADDR_LEN];
	UCHAR ResponderAddr[MAC_ADDR_LEN];
} TDLS_LINK_IDENT_ELEMENT, *PTDLS_LINK_IDENT_ELEMENT;

typedef struct GNU_PACKED _TDLS_CH_SWITCH_TIMING_ELEMENT {
	USHORT ChSwitchTime;
	USHORT ChSwitchTimeOut;
} TDLS_CH_SWITCH_TIMING_ELEMENT, *PTDLS_CH_SWITCH_TIMING_ELEMENT;

typedef struct GNU_PACKED _TDLS_WAKEUP_SCHEDULE_IE {
	UINT32 Interval;
	UINT32 AwakeDuration;
	UINT16 IdleCount;
} TDLS_WAKEUP_SCHEDULE_IE, *PTDLS_WAKEUP_SCHEDULE_IE;

typedef struct GNU_PACKED _TDLS_AP_PHY_DATA_RATE_IE {
	UINT32 AP_PHY_Data_Rate;
} TDLS_AP_PHY_DATA_RATE_IE, *PTDLS_AP_PHY_DATA_RATE_IE;

typedef struct GNU_PACKED _TDLS_CHANNEL_SWITCH_TIMING_IE {
	UINT16 SwitchTime;
	UINT16 SwitchTimeout;
} TDLS_CHANNEL_SWITCH_TIMING_IE, *PTDLS_CHANNEL_SWITCH_TIMING_IE;

#endif /* __DOT11Z_TDLS_H */

#endif /* DOT11Z_TDLS_SUPPORT */
